package net.seabook.games.tetris.model;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

public class Tile {
	
	public enum TileColor {
		RED(Color.RED), YELLOW(Color.YELLOW), BLUE(Color.BLUE), 
		GREEN(Color.GREEN), PURPLE(Color.MAGENTA), 
		ORANGE (Color.ORANGE), PINK (Color.PINK);
		
		private Color color;
		
		private TileColor(Color color) {
			this.color = color;
		}
		
		public static Color getRandomTileColor() {
			TileColor[] colors = TileColor.values();
			Random random = new Random();
			int rad = random.nextInt(colors.length);
			TileColor ranColor = colors[rad];
			return ranColor.color;
		}
	}
	
	public static final int WIDTH = 20;
	public static final int HEIGHT = WIDTH;
	
	private int x;
	private int y;
	private Color filledColor = TileColor.getRandomTileColor();
	
	public Tile(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	public void setTilePosition(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	public void drawSelf(Graphics g) {
		g.setColor(filledColor);
		g.fillRect(x, y, WIDTH, HEIGHT);
		g.setColor(Color.BLACK);
		g.drawRect(x, y, WIDTH, HEIGHT);
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Color getFilledColor() {
		return filledColor;
	}

	public void setFilledColor(Color filledColor) {
		this.filledColor = filledColor;
	}
	
	@Override
	public String toString() {
		return "[x=" + x + "," + "y=" + y + ",color=" + filledColor + "]";
	}
}
